package xyz.mumuwei.youthcourseserver.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.mumuwei.youthcourseserver.common.lang.Result;
import xyz.mumuwei.youthcourseserver.pojo.CourseExperience;
import xyz.mumuwei.youthcourseserver.service.CourseExperienceService;

/**
 * @author mumuwei
 * @since 2022-02-19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/experience")
public class CourseExperienceController {
    final CourseExperienceService experienceService;

    /**
     * 添加课程体验时间
     */
    @PostMapping("")
    public Result add(@Validated CourseExperience experience){
        // Course course1 = courseService.getById(experience.getCourseId());
        // if(course1 == null || course1.getExperienceId() != null){
        //     return Result.fail("课程不存在或已经设置体验时间！");
        // }
        // boolean save = experienceService.save(experience);
        // System.err.println(experience);
        // if (save){
        //     // 设设课程表中的而课程体验时间
        //     Course course = courseService.getById(experience.getCourseId());
        //     course.setExperienceId(experience.getId());
        //     courseService.updateById(course);
        //     return Result.success("添加成功！");
        // }
        return Result.fail("添加失败！");
    }

    /**
     * 修改课程体验时间
     */
    @PostMapping("/update")
    public Result update(CourseExperience experience){
        boolean update = experienceService.updateById(experience);
        if(update){
            return Result.success("更新成功！");
        }
        return Result.fail("更新失败！");
    }

}

